<template>
  <a-popconfirm
      v-if="!option.hide"
      :disabled="option.disabled"
      :title="`您确定要执行 ${option.name} 操作吗？`"
      ok-text="是"
      cancel-text="否"
      @confirm="option.click? option.click(option, $event) : ''"
  >
    <a-button v-has :type="typeCorrect(name, option.type)"
              :disabled="option.disabled"
              :loading="option.loading"
    >
      <template #icon v-if="option.icon">
        <component :is="option.icon" :key="option.icon"/>
      </template>
      {{option.name}}
    </a-button>
  </a-popconfirm>
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue';
import { ActionsOptionItem } from '@/components/typing';

export default defineComponent({
  name: 'ActionButtonConfirm',
  props: {
    name: String,
    option: Object as PropType<ActionsOptionItem>,
    typeCorrect: Function
  },
});
</script>
